package com.example.community.login;

import com.example.community.dao.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/usercontrolpanel")
public class UserControlpanelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        // 获取用户总数
//        UsersDao usersDao = new UsersDao();
//        int usersize = usersDao.fandByAll().size();
//
//        // 获取房间总数
//        RoomDao roomDao = new RoomDao();
//        int roomsize = roomDao.fandByAll().size();
//
//        // 获取车位总数
//        ParkingDao parkingDao = new ParkingDao();
//        int parkingsize = parkingDao.fandByAll().size();
        Integer currentUserUsNo = (Integer) req.getSession().getAttribute("currentUserUsNo");

        // 获取投诉总数
        ComplaintDao complaintDao = new ComplaintDao();
        int complaintsize = complaintDao.fandAllByUsNo(currentUserUsNo).size();
        int complaintsizestate = complaintDao.fandAllByUsNoStatic(currentUserUsNo).size();


        // 维修总数
        RepairDao repairDao = new RepairDao();
        int repairsize = repairDao.fandByAllByUsNo(currentUserUsNo).size();
        int repairsizeStatic = repairDao.fandByAllByUsNoStatic(currentUserUsNo).size();

        // 账单总数
        PaymanagerDao paymanagerDao = new PaymanagerDao();
        int paysize = paymanagerDao.fandByAllByUsNo(currentUserUsNo).size();
        int paysizeStatic = paymanagerDao.fandByAllByUsNoStatic(currentUserUsNo).size();

//        req.setAttribute("usersize",usersize);
//        req.setAttribute("roomsize",roomsize);
//        req.setAttribute("parkingsize",parkingsize);
        req.setAttribute("complaintsize",complaintsize);
        req.setAttribute("repairsize",repairsize);
        req.setAttribute("paysize",paysize);


        req.setAttribute("complaintsizestate",complaintsizestate);
        req.setAttribute("repairsizeStatic",repairsizeStatic);
        req.setAttribute("paysizeStatic",paysizeStatic);

        req.getRequestDispatcher("/WEB-INF/userHome/usercontrolpanel.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
